package kr.pfg.pfgTracer.view.workspace
{
	import flash.display.Sprite;
	
	import kr.pfg.pfgTracer.model.vo.EchoClient;

	public class VWorkSpaceManager extends Sprite
	{
		private var bg: Sprite;
		
		private var arrWorkspace: Array;
		public function VWorkSpaceManager()
		{
			this.init();
		}
		private function init(): void
		{
			bg = new Sprite();
			bg.graphics.beginFill( 0xFFFFFF, 1 );
			bg.graphics.drawRect( 0, 0, 10, 10 );
			bg.graphics.endFill();
			
			arrWorkspace = new Array();
			
			this.setPosition();
			this.initChild();
		}
		private function setPosition(): void
		{			
			bg.x = -bg.width;
			for( var i: int = 0; i < arrWorkspace.length; i ++ )
			{
				arrWorkspace[i].x = - arrWorkspace[i].width;
			}
		}
		private function initChild(): void
		{
			this.addChild( bg );
		}
		
		override public function set width(value:Number):void
		{
			bg.width = value;	
			for( var i: int = 0; i < arrWorkspace.length; i ++ )
			{
				arrWorkspace[i].width = value;
			}
			this.setPosition();
		}
		override public function set height(value:Number):void
		{
			bg.height = value;
			for( var i: int = 0; i < arrWorkspace.length; i ++ )
			{
				arrWorkspace[i].height = value;
			}
			this.setPosition();
		}
		public function setData ( message: String, type: String, key: String ): void
		{
			//textAreaMember[ key ].text ( message, type )
			for( var i: int = 0; i < arrWorkspace.length; i ++ )
			{
				if( arrWorkspace[i].key == key )
					arrWorkspace[i].setData( message, type );
			}
		}
		public function addWorkspace( data: EchoClient ): void
		{
			var workspace: VWorkSpace = new VWorkSpace();
			workspace.key = data.key;
			workspace.fileName = data.swfMember[0];
			workspace.width = bg.width;
			workspace.height = bg.height;
			arrWorkspace.push( workspace );
			workspace.x = -workspace.width;
			
			this.addChild( workspace );
		}
		public function changeWorkspace( key: String ): void
		{
			for( var i: int = 0; i < arrWorkspace.length; i ++ )
			{
				arrWorkspace[i].visible = false;;
				if( arrWorkspace[i].key == key )
					arrWorkspace[i].visible = true;
			}
		}
	}
}